package com.erpanderp.wam.tm.model.service;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.FlushMode;
import org.hibernate.Query;
import org.hibernate.Session;

import com.erpanderp.wam.tm.model.entity.RRFSelectedSkillsList;
import com.erpanderp.wam.usm.model.entity.user.Employee;
import com.erpanderp.wam.util.HibernateUtil;

public class RRFSelectedSkillsListDAO {
	
	public RRFSelectedSkillsList createRRFSelectedSkills(RRFSelectedSkillsList rrfSelectedSkill){
		System.out.println("rrfSelectedSkill========INSIDE DAO=========="+rrfSelectedSkill);
		try{
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.getTransaction().begin();
		System.out.println("FLUSH MODE: " + session.getFlushMode());
		session.setFlushMode(FlushMode.COMMIT);
		session.save(rrfSelectedSkill);
		session.getTransaction().commit();
		return rrfSelectedSkill;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}		
	}
	
	 public List<RRFSelectedSkillsList> getSelectedSkillsByRRFCode(String rrfCode){ 

			List<RRFSelectedSkillsList> primarySkills = new ArrayList<RRFSelectedSkillsList>();
System.out.println("INSIDE DAO:::::::+++++"+rrfCode);			
			try{
				Session session = HibernateUtil.getSessionFactory().getCurrentSession();
				session.beginTransaction();
				session.setFlushMode(FlushMode.COMMIT);
				String queryString = "from RRFSelectedSkillsList sl where sl.recruitmentRequestCode = :rrfCode";
				
				Query query = session.createQuery(queryString);
				query.setCacheable(false).setString("rrfCode", rrfCode);
				
				primarySkills =(List<RRFSelectedSkillsList>) query.list();
			
				session.getTransaction().commit();
				return primarySkills;	
			}catch(Exception e){
				e.printStackTrace();
				return null;
			}		
		}
	 
	 public RRFSelectedSkillsList getRRFSelectedSkillsListBySkillId(Long skillId){ 
		 RRFSelectedSkillsList rrfSelectedSkillsList ;		
			try{
				Session session = HibernateUtil.getSessionFactory().getCurrentSession();
				session.beginTransaction();
				session.setFlushMode(FlushMode.COMMIT);
				String queryString = "from RRFSelectedSkillsList sl where sl.rrfSelectedSkillsListId = :skillId";
				
				Query query = session.createQuery(queryString);
				query.setCacheable(false).setLong("skillId", skillId);			
				rrfSelectedSkillsList = (RRFSelectedSkillsList) query.uniqueResult();
				session.getTransaction().commit();
				
				return rrfSelectedSkillsList;
				
			} catch (Exception e) {
				e.printStackTrace();
				return null;
			}	
		}

}
